package cn.microservices.cloud.gateway.util.token;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class Token implements Serializable {

//	private Long serialVersionUID = -123L;

	private final String key;

	private final String subjectId;

	private final String subjectClass;

	private final Long expiresIn;

	private Map<String, Serializable> attributes = new HashMap<>();

	public Token(String subjectId, String subjectClass) {
		this(subjectId, subjectClass, null);
	}

	public Token(String subjectId, String subjectClass, Map<String, Serializable> attributes) {
		this.subjectId = subjectId;
		this.subjectClass = subjectClass;
		this.key = UUID.randomUUID().toString().replace("-", "");
		this.expiresIn = System.currentTimeMillis() + TokenManager.getTokenValidSeconds() * 1000;
		if (attributes != null)
			this.attributes = attributes;
	}

	public String getKey() { return key; }

	public String getSubjectId() { return subjectId; }

	public String getSubjectClass() { return subjectClass; }

	public Long getExpiresIn() { return expiresIn; }

	public Serializable getAttribute(String key) { return attributes.get(key); }
}
